#pragma once
#include "stdafx.h"
class Pawn;
class ModelComponentDesc
	:public ActorDesc
{
public:
	string ModelName;
	bool bReflects, bRefracts;
	float DiffuseFactor;
	ModelComponentDesc() : ActorDesc()
	{
		bReflects=bRefracts=false;
		DiffuseFactor=0;
	}
};
class ModelComponent
	: public Actor
{
public:
	ModelComponent(ModelComponentDesc&);
	sptr<GameResource> Model;
	bool bReflects, bRefracts;
	float DiffuseFactor;
	void LoadShaderVars(sptr<GameResource> shader_resc);
	Pawn* Owner;
};
class PawnDesc
	:public ActorDesc
{
public:
	PawnDesc() : ActorDesc()
	{
		bHasCloth=bKinematic=bAI=false;
		bVisible=true;
	}
	bool bHasCloth, bKinematic, bAI, bVisible;
	NxClothDesc ClothDesc;
	Vec3 ClothDimensions;
	string ClothMaterialName;
	std::vector<ModelComponentDesc> ModelDescs;
};
class Pawn :
	public Actor
{
public:
	Pawn(PawnDesc&);
	~Pawn(void);
	bool bAI, bKinematic, bAggroed, bVisible, bReturning;
	float AggroRange, AIPause;
	sptr<Cloth> cloth;
	sptr<GameResource> ClothMaterialResc;
	sptr<NxShapeDesc> GetShape(sptr<GameResource> model_resc);
	BBVector<sptr<ModelComponent>> Models;
	Vec3 AITarget;
	void AI();
	virtual void Update(double dt);
	virtual void React(Pawn*);
};
class SensorReport : public NxUserTriggerReport
{
	virtual void onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status)
	{
		NX_ASSERT(triggerShape.getFlag(NX_TRIGGER_ENABLE));
		if(status & NX_TRIGGER_ON_ENTER)
		{
			NxActor& actor = otherShape.getActor();
			if(actor.userData)
			{
				NxActor& triggerActor = triggerShape.getActor();
				if(triggerActor.userData!=NULL)
				{
					Pawn *pawn_1 = (Pawn*)triggerActor.userData, *pawn_2 = (Pawn*)actor.userData;
					pawn_1->React(pawn_2);
					pawn_2->React(pawn_1);
				}
			}
		}
		if(status & NX_TRIGGER_ON_LEAVE)
		{
			NxActor& actor = otherShape.getActor();
			if(actor.userData)
			{
				NxActor& triggerActor = triggerShape.getActor();
				if(triggerActor.isDynamic() && triggerActor.userData != NULL)
				{
					Pawn *pawn_1 = (Pawn*)triggerActor.userData, *pawn_2 = (Pawn*)actor.userData;
					pawn_1->React(pawn_2);
					pawn_2->React(pawn_1);
				}
			}
		}
	}
};

